<?php

/**
 * Group models
 *
 * Group models in data
 *
 * PHP Version: 1.2.3
 *
 * @author Johari <joharijumali@gmail.com>
 */

/**
 * Class Group
 *
 * Class Group in data models
 *
 * @author Johari <joharijumali@gmail.com>
 */

class Data_Attendance_Group extends Eloquent
{

    public static $timestamps = false;
    public static $table = 'sys_user_kumpulan_pekerja';
    public static $key = 'sukp_no_auto';

	/**
     * Function listGroup
	 *
	 * @return listGroup.
     */
    public static function listGroup()
	{
        $allFlow = Data_Attendance_Group::order_by('sukp_no_kumpulan','ASC')
			->paginate(Config::get('system.pagination'));

        $datagrid = new Datagrid;
        $datagrid->setFields(array('sukp_no_kumpulan' => Str::upper(Lang::line('admin.staffgroup')->get())));
        $datagrid->setFields(array('sukp_penerangan' => Str::upper(Lang::line('global.desc')->get())));
        $datagrid->setAction(Lang::line('global.manage')->get(), 'groupcalendar');
        $datagrid->setAction(Lang::line('global.edit')->get(), 'editGroupData', true, array(static::$key));
        $datagrid->setAction(Lang::line('global.delete')->get(), 'deleteGroup', true, array(static::$key, 'sukp_no_kumpulan'));
        $datagrid->setTable('group', 'table table-bordered table-hover table-striped table-condensed');
        $datagrid->showNumbering(true);
        $datagrid->build($allFlow, static::$key);

        return $datagrid->render();
    }

	/**
     * Function addGetId that pass parameter
     *
     * @param varchar $input the varchar to quote
	 *
	 * @return parameter.
     */
    public static function addGetId($input)
	{
        $schedule = new Data_Attendance_Group;
        
        $id = $schedule->insert_get_id(array(
			'sukp_no_kumpulan' => $input['wjkp_no_kumpulan'],
            'sukp_penerangan' => $input['wjkp_penerangan'], 
            'sukp_tarikh_cipta' => date("Y-m-d H:i:s"),
            'sukp_cipta_oleh' => Auth::user()->su_id,
            'sukp_kemaskini_oleh' => Auth::user()->su_id
		));

        $action = Lang::line('global.add')->get().' '.Lang::line('admin.staffgroupschedule')->get().' 
			<strong>'.$input['wjkp_no_kumpulan'].'</strong>';
        Log::write(Lang::line('admin.staffgroupschedule')->get(), $action.' By <code>'.Auth::user()->su_username.'</code>');
		Trail::log(Lang::line('admin.staffgroupschedule')->get(), Auth::user()->su_id, $action.' Oleh <code>'.Auth::user()->su_username.'</code>');
		
        return $id;
    }
	
	/**
     * Function updateGroup that pass parameter
     *
     * @param varchar $input the varchar to quote
	 *
	 * @return parameter.
     */
    public static function updateGroup($input)
	{
        $schedule = Data_Attendance_Group::find($input['wjkp_no_auto']);
        $action = Lang::line('global.edit')->get().' '.Lang::line('admin.staffgroupschedule')->get().' 
			<strong>'.$input['wjkp_no_kumpulan'].'</strong>';

        $schedule->sukp_no_kumpulan = $input['wjkp_no_kumpulan'];
        $schedule->sukp_penerangan = $input['wjkp_penerangan'];
        $schedule->sukp_kemaskini_oleh = Auth::user()->su_id;
        $schedule->save();

        Log::write(Lang::line('admin.staffgroupschedule')->get(), $action.' By <code>'.Auth::user()->su_username.'</code>');
		Trail::log(Lang::line('admin.staffgroupschedule')->get(), Auth::user()->su_id, $action.' Oleh <code>'.Auth::user()->su_username.'</code>');
    }
	
	/**
     * Function groupInfo that pass parameter
     *
     * @param integer $id the integer to quote
	 *
	 * @return parameter.
     */
    public static function groupInfo($id)
	{
        $schedule = Data_Attendance_Group::find($id);

        $data['wjkp_no_kumpulan'] = $schedule->sukp_no_kumpulan;
        $data['wjkp_penerangan'] = $schedule->sukp_penerangan;
        $data['wjkp_no_auto'] = $schedule->sukp_no_auto;

        return $data;
    }
	
	/**
     * Function arrayGroup
	 *
	 * @return arrayGroup.
     */
    public static function arrayGroup()
    {
        $deptlist = Data_Attendance_Group::order_by('sukp_penerangan', 'asc')->get();

        $arrayDept = array(Lang::line('global.pleasechoose')->get());

        foreach ($deptlist as $value) {
            $arrayDept[$value->sukp_no_auto] = $value->sukp_penerangan;
        }

        return $arrayDept;
    }
	
	public static function deleteGroup($input)
	{
        Data_Attendance_Group::find($input['id'])->delete();

        Log::write(
			Lang::line('admin.staffgroupschedule')->get(), 
			Lang::line('global.delete')->get().' <strong>'.$input['name'].'</strong> 
			'.Lang::line('global.by')->get().' <code>'.Auth::user()->su_username.'</code>'
		);
		Trail::log(
			Lang::line('admin.staffgroupschedule')->get(), 
			Auth::user()->su_id, 
			Lang::line('global.delete')->get().' <strong>'.$input['name'].'</strong> 
			'.Lang::line('global.by')->get().' <code>'.Auth::user()->su_username.'</code>'
		);
    }

}

?>